<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	public function index(){

		if(isset($_SESSION['username'])){
        	$this->assign('login','true');
        	$this->assign('username',$_SESSION['username']);
        }

      //当前登录用户的id
      $userid=$_SESSION['id'];

      $cart = D('cart');
      $count = $cart->where("userid='$userid' ")->count();
      $this->assign('count',$count);

      

      $cartArr = $cart->where("userid='$userid' ")->order('id desc')->select();
      $total = 0;
      foreach ($cartArr as $item) {
          $total += $item['discountprice'] * $item['count'];
      }
      $this->assign('total',$total);



		$this->display();
	}

     //退出
    public function doLogout(){
        $_SESSION = array();
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'',time()-1,'/');
        }
        session_destroy();
        $this->redirect('Index/index');
    }
}